package com.ghck.server.bkcontroller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ghck.server.aop.PathAndMsgOnError;
import com.ghck.server.model.Message;
import com.ghck.server.service.MessageService;

/**
 * 
 * @author chenxuan
 *
 */
@Controller
@RequestMapping(value="/admin/message")
public class AdminMessageController {

	private static Logger logger = LoggerFactory.getLogger(AdminMessageController.class);
	@Autowired
	private MessageService messageService;
	
	@RequestMapping(value="/toAdd")
	public String toAdd(){
		return "back/message/add";
	}
	
	@PathAndMsgOnError(path="/back/message/add",errorMsgField="errorMsg")
	@RequestMapping(value="/add")
	public String add(Message message,Model model){
		messageService.pushMessage(message);
		model.addAttribute("msg", "添加成功");
		return "back/message/add";
	}
	
	@RequestMapping(value="/list")
	public String list(Message message,Model model){
		logger.info("startTime : |{}|",message.getStartTime());
		logger.info("endTime : |{}|",message.getEndTime());
		List<Message> list = messageService.list(message);
		model.addAttribute("list", list);
		return "back/message/list";
	}
	
}